home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_01_07 / 1n07045a < prev    next >
Text File  |  1990-11-03  |  3KB  |  130 lines

  1.  
  2.  
  3. /*****************************************************
  4. * NETACTIV.C -- Check for an active network
  5. *
  6. * #define NO_MSC if _osmajor and _osminor are invalid
  7. * compiler variables
  8. *
  9. *     Copyright 1990 Tom Jensen
  10. *****************************************************/
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <dos.h>
  15. #include "netbios.h"
  16.  
  17. /* function prototypes */
  18. unsigned DosVersion (void);
  19. int     NetActive (void);
  20. int     LocalName (char *name);
  21.  
  22. /*******************************************************
  23. * NetActive() -- Display results of network presence
  24. *         test (NbNetActive).
  25. *
  26. * Exit: Returns same value returned by NbNetActive.
  27. *******************************************************/
  28.  
  29. int NetActive (void)
  30. {
  31.   int        active;
  32.   unsigned  ver;
  33.   char        name [16];
  34.  
  35.   ver = DosVersion();
  36.   printf ("MS-DOS version is %d.%d", ver/100, ver % 100);
  37.  
  38.   active = NbNetActive();
  39.   switch (active)
  40.   {
  41.     case 2:
  42.       printf (" ... must be 3.10 or greater\n");
  43.       break;
  44.     case 1:
  45.       printf ("\nNetwork is not active\n");
  46.       break;
  47.     default:
  48.       printf ("\nNetwork is active\n");
  49.       if (LocalName (name))
  50.     printf ("Local network name is \"%s\"\n", name);
  51.       else
  52.     printf ("No local network name defined\n");
  53.   }
  54.   return active;
  55. }
  56.  
  57. /*******************************************************
  58. * NbNetActive() -- Determine if DOS compatible network
  59. *           is active.
  60. *
  61. * Exit: If return value == 0, possible NETBIOS network
  62. *      is active
  63. *    else
  64. *      if == 1, network not active.
  65. *      if == 2 if DOS < 3.10.
  66. *******************************************************/
  67.  
  68. int NbNetActive (void)
  69. {
  70.   int    retval = 0;
  71.   char    loc_dev[16], net_nam[128];
  72.   union REGS  cpuregs;
  73.  
  74.   if (DosVersion() < 310)
  75.     retval = 2;
  76.   else
  77.   {
  78.     cpuregs.x.ax = 0x5f02;
  79.     cpuregs.x.bx = 0;
  80.     cpuregs.x.di = (unsigned)net_nam;
  81.     cpuregs.x.si = (unsigned)loc_dev;
  82.     intdos (&cpuregs, &cpuregs);
  83.     if (cpuregs.x.cflag && (cpuregs.x.ax == 1))
  84.       retval = 1;
  85.   }
  86.   return retval;
  87. }
  88.  
  89. /***************************************************
  90. * LocalName() -- Get local network name from MS-DOS
  91. *
  92. *     Entry: name points to a 16 character buffer
  93. *
  94. *     Exit:  Returns 0 (false) if no local network
  95. *         name is defined. Otherwise the name
  96. *         buffer will contain the network name.
  97. ***************************************************/
  98.  
  99. int LocalName (char *name)
  100. {
  101.   union REGS  cpuregs;
  102.  
  103.   cpuregs.x.ax = 0x5e00;
  104.   cpuregs.x.dx = (unsigned)name;
  105.   intdos (&cpuregs, &cpuregs);
  106.  
  107.   return (cpuregs.h.ch);
  108. }
  109.  
  110. /***************************************************
  111. * DosVersion() -- Get MS-DOS version number
  112. *
  113. *     Exit: return value == version number * 100
  114. ***************************************************/
  115.  
  116. unsigned DosVersion (void)
  117. {
  118. #ifdef NO_MSC
  119.   unsigned    ver;
  120.   union REGS  cpuregs;
  121.  
  122.   cpuregs.h.ah = 0x30;
  123.   ver = intdos (&cpuregs, &cpuregs);
  124.   return (((ver & 0xff) * 100) + (ver >> 8));
  125. #else
  126.   return (_osmajor * 100 + _osminor);
  127. #endif
  128. }
  129.  
  130.